//
//  CheckoutViewController.m
//  ExhibitForcePrototype
//
//  Created by Vladimir Tsenev on 12/5/12.
//  Copyright (c) 2012 Dilyana Todorova. All rights reserved.
//

#import "CheckoutViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "MMScanBadgeViewController.h"

@interface CheckoutViewController ()

@property (strong, nonatomic) IBOutlet UIView *infoView;
@property (strong, nonatomic) CAGradientLayer *gradient;

- (void)configureGradient;

@end

@implementation CheckoutViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.infoView.layer.borderWidth = 2;
    self.infoView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    self.infoView.layer.cornerRadius = 1;
    [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonTapped)]];
    [self configureGradient];
}
- (IBAction)sendButtonPressed:(id)sender {
    [[self.navigationController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)scanButtonPressed:(id)sender {
//    [[self.navigationController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
    MMScanBadgeViewController *svc = [[MMScanBadgeViewController alloc] initWithNibName:@"MMScanBadgeViewController" bundle:nil];
    [[self navigationController] pushViewController:svc animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - private methods

- (void)configureGradient
{
    self.gradient = [CAGradientLayer layer];
    self.gradient.frame = self.infoView.bounds;
    
    UIColor *firstColor  = [UIColor colorWithWhite:1.0 alpha:1.0];
    UIColor *secondColor = [UIColor colorWithWhite:0.9 alpha:1.0];
    
    self.gradient.colors = [NSArray arrayWithObjects:(id)[firstColor CGColor], (id)[secondColor CGColor], nil];
    [self.infoView.layer insertSublayer:self.gradient atIndex:0];
    self.infoView.layer.masksToBounds = YES;
}

#pragma mark - action handler
-(void)cancelButtonTapped
{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
@end
